package com.tea.funct.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tea.common.annotation.Log;
import com.tea.common.core.controller.BaseController;
import com.tea.common.core.domain.AjaxResult;
import com.tea.common.enums.BusinessType;
import com.tea.funct.domain.TeaRewardRecord;
import com.tea.funct.service.ITeaRewardRecordService;
import com.tea.common.utils.poi.ExcelUtil;
import com.tea.common.core.page.TableDataInfo;

/**
 * 奖励记录Controller
 * 
 * @author Sophia
 * @date 2024-05-31
 */
@RestController
@RequestMapping("/funct/rewards")
public class TeaRewardRecordController extends BaseController
{
    @Autowired
    private ITeaRewardRecordService teaRewardRecordService;

    /**
     * 查询奖励记录列表
     */
    @PreAuthorize("@ss.hasPermi('funct:rewards:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaRewardRecord teaRewardRecord)
    {
        startPage();
        List<TeaRewardRecord> list = teaRewardRecordService.selectTeaRewardRecordList(teaRewardRecord);
        return getDataTable(list);
    }

    /**
     * 导出奖励记录列表
     */
    @PreAuthorize("@ss.hasPermi('funct:rewards:export')")
    @Log(title = "奖励记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaRewardRecord teaRewardRecord)
    {
        List<TeaRewardRecord> list = teaRewardRecordService.selectTeaRewardRecordList(teaRewardRecord);
        ExcelUtil<TeaRewardRecord> util = new ExcelUtil<TeaRewardRecord>(TeaRewardRecord.class);
        util.exportExcel(response, list, "奖励记录数据");
    }

    /**
     * 获取奖励记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('funct:rewards:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(teaRewardRecordService.selectTeaRewardRecordById(id));
    }

    /**
     * 新增奖励记录
     */
    @PreAuthorize("@ss.hasPermi('funct:rewards:add')")
    @Log(title = "奖励记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaRewardRecord teaRewardRecord)
    {
        return toAjax(teaRewardRecordService.insertTeaRewardRecord(teaRewardRecord));
    }

    /**
     * 修改奖励记录
     */
    @PreAuthorize("@ss.hasPermi('funct:rewards:edit')")
    @Log(title = "奖励记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaRewardRecord teaRewardRecord)
    {
        return toAjax(teaRewardRecordService.updateTeaRewardRecord(teaRewardRecord));
    }

    /**
     * 删除奖励记录
     */
    @PreAuthorize("@ss.hasPermi('funct:rewards:remove')")
    @Log(title = "奖励记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teaRewardRecordService.deleteTeaRewardRecordByIds(ids));
    }
}
